﻿Imports DAL
Public Class ListeEmployeAffinite
    Public beneficiaireSelectionne As Beneficiaire
    Public ControlAppel As ComboBox
    Private Class EmployeParAffinite
        Public Employe As Employe
        Public NbrAffinite As Integer
    End Class

    Private Sub ListeEmployeAffinite_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Me.DesignMode Then
            Dim emp As New List(Of EmployeParAffinite)
            ListView1.Items.Clear()
            For Each employe In bd.Employes
                Dim nbrAffinite = (From a In employe.EmployeAffinites Where (From b In beneficiaireSelectionne.BeneficiaireAffinites Select b.Affinite).Contains(a.Affinite) Select a).Count
                Dim employeParAffinite As New EmployeParAffinite
                employeParAffinite.Employe = employe
                employeParAffinite.NbrAffinite = nbrAffinite
                emp.Add(employeParAffinite)
            Next
            For Each Employe In emp.OrderByDescending(Function(x) x.NbrAffinite)
                Dim item As New ListViewItem
                item.Text = Employe.Employe.Nom + ", " + Employe.Employe.Prenom
                item.SubItems.Add(Employe.NbrAffinite)
                item.Tag = Employe.Employe.ID
                ListView1.Items.Add(item)
            Next
        End If
    End Sub

    Private Sub ListView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.DoubleClick, BtChoisir.Click
        If ListView1.SelectedItems.Count > 0 Then
            ControlAppel.SelectedValue = ListView1.SelectedItems(0).Tag
            Me.Close()
        End If
    End Sub

    Private Sub BtAnnuler_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtAnnuler.Click
        Me.Close()
    End Sub
End Class